package com.xuyuan.interview.scene.api;

import com.xuyuan.interview.scene.entity.Order;
import com.xuyuan.interview.scene.entity.Product;
import lombok.Data;

import java.util.Objects;

@Data
public abstract class CouponCondition implements Coupon {
    public Integer userLevel;
    public String productId;
    public String productType;

    @Override
    public boolean isSatisfied(Order order, Product product, int userLevel) {
        if (Objects.nonNull(this.productId) && !Objects.equals(this.productId, product.getProductId())) {
            return false;
        }
        if (Objects.nonNull(this.productType) && !Objects.equals(this.productType, product.getProductType())) {
            return false;
        }
        if (Objects.nonNull(this.userLevel) && this.userLevel < userLevel) {
            return false;
        }
        return true;
    }
}